package com.facefun.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.facefun.Enum.StateCode;
import com.facefun.dao.StoreMapper;
import com.facefun.domain.Cartoon;
import com.facefun.domain.Store;
import com.facefun.service.StoreService;
import com.github.pagehelper.ISelect;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class StoreServiceImpl extends BaseService<Store> implements StoreService {

	@Override
	public StateCode addStore(Store store) {
		if(save(store)!=0){
			return StateCode.SUCCESS;
		}
		return StateCode.Error;
	}

	@Override
	public StateCode removeStore(Store store) {
		if(mapper.delete(store)!=0){
			return StateCode.SUCCESS;
		}
		return StateCode.Error;
	}

	@Override
	public Boolean isStore(Store store) {
		Boolean b=mapper.selectCount(store)!=0;
		return b;
	}

	@Override
	public Map<String, Object> getStoreList(Integer uId,Integer offset,Integer limit) {
		
		Page p=PageHelper.offsetPage(offset, limit).doSelectPage(new ISelect() {
			
			@Override
			public void doSelect() {
				((StoreMapper) mapper).getStoreList(uId);
				
			}
		});
		Map<String,Object> map=new HashMap<>();
		map.put("total", p.getTotal());
		map.put("data", p.getResult());
		return map;
	}

	@Override
	public List<Cartoon> getStoreList(Integer uId) {
		return ((StoreMapper) mapper).getStoreList(uId);
	}

}
